package com.kexio.pay.enums;

/**
 * 支付方式枚举
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
public enum PaymentMethod {
    
    // 微信支付
    WECHAT_NATIVE("wechat_native", "微信Native支付", "wechat"),
    WECHAT_JSAPI("wechat_jsapi", "微信JSAPI支付", "wechat"),
    WECHAT_APP("wechat_app", "微信APP支付", "wechat"),
    WECHAT_H5("wechat_h5", "微信H5支付", "wechat"),
    WECHAT_MINI("wechat_mini", "微信小程序支付", "wechat"),
    
    // 支付宝
    ALIPAY_PC("alipay_pc", "支付宝PC网站支付", "alipay"),
    ALIPAY_WAP("alipay_wap", "支付宝手机网站支付", "alipay"),
    ALIPAY_APP("alipay_app", "支付宝APP支付", "alipay"),
    ALIPAY_QR("alipay_qr", "支付宝扫码支付", "alipay"),
    
    // 银联支付
    UNIONPAY_PC("unionpay_pc", "银联PC支付", "unionpay"),
    UNIONPAY_WAP("unionpay_wap", "银联手机支付", "unionpay"),
    UNIONPAY_QR("unionpay_qr", "银联二维码支付", "unionpay"),
    
    // 其他支付方式
    BALANCE("balance", "余额支付", "balance"),
    CREDIT("credit", "积分支付", "credit");
    
    private final String code;
    private final String description;
    private final String provider;
    
    PaymentMethod(String code, String description, String provider) {
        this.code = code;
        this.description = description;
        this.provider = provider;
    }
    
    public String getCode() {
        return code;
    }
    
    public String getDescription() {
        return description;
    }
    
    public String getProvider() {
        return provider;
    }
    
    /**
     * 根据代码获取枚举
     */
    public static PaymentMethod fromCode(String code) {
        for (PaymentMethod method : values()) {
            if (method.getCode().equals(code)) {
                return method;
            }
        }
        throw new IllegalArgumentException("Unknown payment method code: " + code);
    }
    
    /**
     * 是否为微信支付
     */
    public boolean isWechat() {
        return "wechat".equals(provider);
    }
    
    /**
     * 是否为支付宝
     */
    public boolean isAlipay() {
        return "alipay".equals(provider);
    }
    
    /**
     * 是否为银联支付
     */
    public boolean isUnionpay() {
        return "unionpay".equals(provider);
    }
    
    /**
     * 是否需要跳转
     */
    public boolean needRedirect() {
        return this == ALIPAY_PC || this == ALIPAY_WAP || this == WECHAT_H5 || this == UNIONPAY_PC || this == UNIONPAY_WAP;
    }
    
    /**
     * 是否支持扫码
     */
    public boolean supportQrCode() {
        return this == WECHAT_NATIVE || this == ALIPAY_QR || this == UNIONPAY_QR;
    }
}
